<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <button @click="isHot = !isHot ">切换天气</button>
    <p>今天的天气真{{isHot? "热" : "冷"}}啊</p>
    <img :src="src" width="300px">

    <button @click="obj.age += 10">切换年龄</button>
    <p>{{obj.age}} -- {{obj.name}}</p>
    <p>改变后年龄:{{count}}</p>
    
  </div>
  <script>
    Vue.config.productionTip = false;

    const vm = new Vue({
      el: "#app",
      data() {
        return {
          isHot: true,
          src: '',
          obj: {
            name: "laoliu",
            age: 18
          },
          count: ''
        }
      },
      watch: {
        isHot: {
          // wacth默认只能监视某个属性的变化,并不能在初始化的时候就执行handler函数
          //可以配置immediate属性,让watch在初始化阶段就立即监视
          immediate: true,

          handler(news) {
            this.src = news ? "./re.webp" : "./leng.gif"
          }

        },

        obj: {
          //对 一个对象或者数组监视的时候,内部发送改变并不能触发handler 需要开启深度监视
          deep: true,
          handler(a , b){
            // console.log(a.age , b.age);
            this.count = a.age
          }

        }
      }
    })
  </script>
</body>

</html>